<?php
    function getFPoints($xml_file) {
        global $fpoints;
        $objeto = new DOMDocument();
        $objeto->load($xml_file);
        $filho = $objeto->getelementsbytagname("floatingpoint");
        if ($filho->length > 0) {
            $temp = $filho->item(0)->getelementsbytagname("floatp");
            $j = 0;
            for($i = 0; $i < $temp->length; $i++) {
                $conteudo = $temp->item($i)->getelementsbytagname("decimal");
                if ($conteudo->length > 0) {
                $fpoints[$j] = $temp->item($i);
                $j++;
                }
            }
            return $fpoints;
        }
        else return null;
    }

    function getBase($indice) {
        global $fpoints, $b;
        $base = $fpoints[$indice]->getelementsbytagname("base");
        $b = $base->item(0)->nodeValue;
        return $b;
    }

    function getMantissa($indice) {
        global $fpoints, $m;
        $mantissa = $fpoints[$indice]->getelementsbytagname("mantissa");
        $m = $mantissa->item(0)->nodeValue;
        return $m;
    }

    function getExps($indice) {
        global $fpoints, $e;
        $expoentes = $fpoints[$indice]->getelementsbytagname("exponent");
        $l = $expoentes->item(0)->getelementsbytagname("lower");
        $u = $expoentes->item(0)->getelementsbytagname("upper");
        $e[0] = $l->item(0)->nodeValue;
        $e[1] = $u->item(0)->nodeValue;
        return $e;
    }

    function getDecimals($indice) {
        global $fpoints, $d;
        $decimais = $fpoints[$indice]->getelementsbytagname("decimal");
        $x = $decimais->item(0)->getelementsbytagname("x");
        $d[0] = $x->item(0)->nodeValue;
        $d[1] = $x->item(1)->nodeValue;
        return $d;
    }

    function getDesc($indice) {
        global $fpoints, $desc;
        $descricao = $fpoints[$indice]->getelementsbytagname("description");
        $desc = $descricao->item(0)->nodeValue;
        return $desc;
    }

    function getCom($indice) {
        global $fpoints, $com;
        $comentario = $fpoints[$indice]->getelementsbytagname("comments");
        if ($comentario->length > 0) {
            $com = $comentario->item(0)->nodeValue;
            return $com;
        }
        else return null;
    }

    function getRef($indice) {
        global $fpoints, $ref;
        $referencia = $fpoints[$indice]->getelementsbytagname("reference");
        if ($referencia->length > 0) {
            $ref = $referencia->item(0)->nodeValue;
            return $ref;
        }
        else return null;
    }

    function createMenu() {
        global $fpoints,$msg;
        for($i = 0; $i < sizeof($fpoints); $i++) {
            echo "<a class=bibliotecaexemplos href=javascript:createLinks($i)><u>";
            $temp1 = $i+1;
            echo $msg->get("XML_EXIBE_PTOFLU_MSG01");
            echo "$temp1";
            echo "</u></a><p>";
        }
        return;
    }

    if (empty($xml_file) && empty($id_bib)) $id_bib = "bib_demo.xml";
    if ( (strlen(@$indice)==0) || ($indice == null) ) { ?>

<p>

        <form name="myform" enctype="multipart/form-data" method="post">

        <script language="javascript" type="text/javascript">
            function createLinks(value) {
               document.myform.indice.value = value;
               document.myform.action = 'index.php?inc=subtracaoPF.php&modo=exemplo';
               document.myform.submit();
            }

        </script>

        <? if (isset($id_bib)) $xml_file = $DOCUMENT_ROOT."/bibliotecas/".$id_bib; ?>
        <? verificaBib($xml_file); ?>
        <?  if (file_exists($xml_file)) {
                $temp = getFPoints($xml_file);
                if (!$temp==null) {
                   echo "<p>";
                   echo "<p align=left><font face=Arial>".$msg->get("XML_EXIBE_MSG04")."</font>";
                   echo "<p>";
                   createMenu();
                } else {
                     echo $msg->get("XML_EXIBE_MSG05");
                     echo "<p><input class=button type=button value=".$msg->get("XML_BACK")." onClick=history.back()>";
                }
	    } else {
                 echo $msg->get("XML_EXIBE_MSG06");
                 echo "<p><input class=button type=button value=".$msg->get("XML_BACK")." onClick=history.back()>";
	    }
 	 ?>

        <input type="hidden" name="id_bib" value="<? echo $id_bib ?>">
        <input type="hidden" name="xml_file" value="<? echo $xml_file ?>">
        <input type="hidden" name="indice">
        <input class="button" type="button" value=<? echo $msg->get("XML_EXIBE_MSG07"); ?> onClick="history.back()">
        </form>

<? } else { ?>

<p>

        <form name="myform" enctype="multipart/form-data" method="post">

        <script language="javascript" type="text/javascript">
            function sendToCalculus() {
               document.myform.Calcular.value = 'sim';
               document.myform.action = 'index.php?id_bib=<?echo $id_bib?>&indice=<?echo $indice?>&inc=subtracaoPF.php&modo=exemplo';
               document.myform.submit();
            }

        </script>

        <? getFPoints($xml_file); ?>
        <? $base = getBase($indice);?>
        <? $casas = getMantissa($indice);?>
        <? $temp = getExps($indice); ?>
        <? $expmin = $temp[0]; $expmax = $temp[1]; ?>
        <? $temp = getDecimals($indice); ?>
        <? $num1 = $temp[0]; $num2 = $temp[1]; ?>
        <? $desc = getDesc($indice); ?>
        <? $com = getCom($indice); ?>
        <? $ref = getRef($indice); ?>

        <? verificaBib($xml_file); ?>
        <? if (!strlen($desc) == 0) { ?>
              <p align="left"><font face="Arial"><b><? echo $msg->get("XML_EXIBE_PTOFLU_MSG02"); ?> </b><? echo htmlentities(utf8_decode($desc)) ?></font>
        <? } ?>
        <p>
		<p align="center"><font face="Arial"><? echo $msg->get("XML_EXIBE_PTOFLU_MSG08"); ?> <br></font>
		
		<font face="Arial">b = </font><input type="text" size="4" maxlenght="6" name="base" value="<? echo $base ?>">&nbsp;&nbsp;
		<font face="Arial">m = </font><input type="text" size="4" maxlenght="6" name="casas" value="<? echo $casas ?>">&nbsp;&nbsp;
		<font face="Arial">e</font><sub>inf</sub> = <input type="text" size="4" maxlenght="6" name="expmin" value="<? echo $expmin ?>">&nbsp&nbsp
		<font face="Arial">e</font><sub>sup</sub> = <input type="text" size="4" maxlenght="6" name="expmax" value="<? echo $expmax ?>"><p>
		<font face="Arial">X</font><sub>1</sub><font face="Arial"> (<? echo $msg->get("XML_EXIBE_PTOFLU_MSG04"); ?>) </font>= <input type="text" size="10" maxlenght="20" name="num1" value="<? echo $num1 ?>"><p>
        <font face="Arial">X</font><sub>2</sub><font face="Arial"> (<? echo $msg->get("XML_EXIBE_PTOFLU_MSG04"); ?>) </font>= <input type="text" size="10" maxlenght="20" name="num2" value="<? echo $num2 ?>">
		<p>
        <? if (!$com == null) { ?>
              <p align="left"><font face="Arial"><b><? echo $msg->get("XML_EXIBE_MSG08");?></b><? echo htmlentities(utf8_decode($com)) ?></font>
        <? } ?>
        <p>
        <? if (!$ref == null) { ?>
              <p align="left"><font face="Arial"><b><? echo $msg->get("XML_EXIBE_MSG09"); ?> </b><? echo htmlentities(utf8_decode($ref)) ?></font>
        <? } ?>
        <p>

        <input type="hidden" name="xml_file" value="<? echo $xml_file ?>">
        <input type="hidden" name="Calcular" >
    <input type="hidden" name="navegacao" value="sim">
    <input class="button" type="button" value=<? echo $msg->get("XML_EXIBE_MSG010"); ?> onClick="sendToCalculus()"><p>
    </form>
<?
    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
    echo "function criarLinks(value) {\n";
    echo "document.exemplos.indice.value = value;\n";
    echo "document.exemplos.action = 'index.php?inc=subtracaoPF.php&modo=exemplo'\n";
    echo "document.exemplos.submit();\n";
    echo "}\n";
    echo "</script>";
    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
    echo "<input type=\"hidden\" name=\"indice\">";
    echo "<br><br>".$msg->get("Outros_Exemplos")."<br>";
    $objeto = new DOMDocument();
    $objeto->load($xml_file);
    $filho = $objeto->getelementsbytagname("floatingpoint");
    if ($filho->length > 0)
    {
        $temp = $filho->item(0)->getelementsbytagname("floatp");
        $j = 0;
        for($i = 0; $i < $temp->length; $i++)
        {
            $conteudo = $temp->item($i)->getelementsbytagname("decimal");
            if ($conteudo->length > 0)
            {
                if ($j != 0) echo " | ";
                if ($j == $indice) echo "<b>";
                echo "<a href=\"javascript:criarLinks($j)\"><u>".($j+1)."</u></a>";
                if ($j == $indice) echo "</b>";
                $j++;
            }
        }
    }
    echo "<br><br>";
?>

<? } ?>
